<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Adminmenu extends Model
{
    public $table = 'adminmenu';
    public $timestamps = false;

    public static function getChildMenuByParentid($id){
          $where['parentid'] = $id;
          $where['is_open'] = 1;
          $data = static ::where($where)->get();
          return $data;
    }

    /**
     * 返回首页菜单
     */
    public static function getMenu(){
         $mainwhere['parentid'] = 0;
         $mainwhere['is_open'] = 1;
         $menu = static ::where($mainwhere)->orderBy('id','asc')->get();
         if (empty($menu)) {
              return [];
         }
         $menu = $menu->toArray();
         foreach ($menu as $key=>$v){
               $mainwhere['parentid'] = $v['id'];
               $childdata = static ::where($mainwhere)->get();
               if ($childdata){
                   $childdata = $childdata->toArray();
               }
               $menu[$key]['voo'] = $childdata;
         }

         return $menu;
    }
}
